package com.github.raffle.zookeeper;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.util.concurrent.CountDownLatch;

/**
 * @author Stephen Liu
 * @version 1.0.0
 * @since 2017/5/22
 */
public class ZkSync implements Watcher {

    private CountDownLatch latch = new CountDownLatch(1);

    public static void main(String[] args) throws Exception {
        ZooKeeper zk = new ZooKeeper("192.168.33.10:2181", 500, new ZkSync());
        System.out.println("status : " + zk.getState());
    }

    @Override
    public void process(WatchedEvent event) {

        if (Event.KeeperState.SyncConnected == event.getState()) {
            latch.countDown();
        }
    }
}
